package com.lazy.core.service.impl;

import com.lazy.core.entity.RunnerInfo;
import com.lazy.utils.excel.AbstractExportExcelService;
import org.apache.poi.hssf.usermodel.*;
import org.springframework.stereotype.Service;

import java.util.List;

@Service(value="exportRunnerInfoService")
public class ExportRunnerInfoServiceImpl extends AbstractExportExcelService {

	@Override
	public void exportData(HSSFSheet sheet, String[] title, List<?> listContent, HSSFWorkbook workbook) {
		HSSFRow row = sheet.createRow((int) 0);  
		row.setHeight((short) (450));
		HSSFCell cell = null;
		HSSFCellStyle styleTitileCenter = styleTitileCenter(workbook);
		for (int i = 0; i < title.length; i++) {
			//根据内容自动设置列宽    
			if(i==2 || i==5 || i==6 || i==7){
			    sheet.setColumnWidth(i, 7000);  
			}else{
			    sheet.setColumnWidth(i, 3000);  
			}
			cell = row.createCell(i);
			cell.setCellValue(title[i]);
			cell.setCellStyle(styleTitileCenter);
		}
		
		HSSFCellStyle styleTextCenter = styleTextCenter(workbook);
		for(int i =0;i<listContent.size();i++){
			int j = 0;
			row = sheet.createRow(i+1); 
			row.setHeight((short) (450));
			RunnerInfo runnerInfo = (RunnerInfo)listContent.get(i);
			createCell(row, j++, String.valueOf(i+1), styleTextCenter);
			createCell(row, j++, strFormat(runnerInfo.getName()), styleTextCenter);
			createCell(row, j++, strFormat(runnerInfo.getGender()), styleTextCenter);
			createCell(row, j++, strFormat(runnerInfo.getBirth()), styleTextCenter);
			createCell(row, j++, strFormat(runnerInfo.getPhone()), styleTextCenter);
			createCell(row, j++, strFormat(runnerInfo.getEmail()), styleTextCenter);
			createCell(row, j++, strFormat(runnerInfo.getIdType()), styleTextCenter);
			createCell(row, j++, strFormat(runnerInfo.getIdNo()), styleTextCenter);
			createCell(row, j++, strFormat(runnerInfo.getNationality()),styleTextCenter);
			createCell(row, j++, strFormat(runnerInfo.getAddress()), styleTextCenter);
			createCell(row, j++, strFormat(runnerInfo.getEmergencyContactPerson()), styleTextCenter);
			createCell(row, j++, strFormat(runnerInfo.getEmergencyContactTel()), styleTextCenter);
			createCell(row, j++, strFormat(runnerInfo.getBloodType()), styleTextCenter);
			createCell(row, j++, strFormat(runnerInfo.getTShirtSize()), styleTextCenter);
			createCell(row, j++, strFormat(runnerInfo.getPersonalBest()), styleTextCenter);
			createCell(row, j++, strFormat(runnerInfo.getRunnerType()), styleTextCenter);
		}
	}

}
